/**
 * @(#) DExpenseListProxy.as
 *
 * @date		2009. 03. 11.
 * @version		1.0
 * @author		Park, JuneHo
 * @description	 계약현황 조회 - Proxy
 *
 */
package com.skt.common_hr.holotreq.model
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.holotreq.model.vo.DExpenseListVO;
	import com.wcl.dataloader.*;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class DExpenseListProxy extends CommonProxy
	{
		public static const NAME:String = "DExpenseListProxy";

		public static const LOAD_DINNER_LIST_COMPLETE:String = "loadDinnerListComplete";
		public static const LOAD_DINNER_LIST_FAILED:String = "loadDinnerListFailed";

		public var dinnerList:ArrayCollection;
		public var otList:ArrayCollection;
		
		public var daysOfConfirm:Number;
		public var possible:String;
		public var BEGDA:Date;
		public var ENDDA:Date;

		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function DExpenseListProxy(data:Object=null)
		{
			super(NAME, data);
		}


		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 *
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, sDate:Date):void
		{
			var param:Object = new Object(); 
			param["I_PERNR"] = Variables.myPernr;
			param["I_BEGDA"] = DateUtil.toBasicString(DateUtil.firstDateOfMonth(sDate));
			param["I_ENDDA"] = DateUtil.toBasicString(DateUtil.endOfMonth(sDate));
			loadData("Z_HR_0147", param, result, fault);
		}










		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////

		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 *
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(event.result["RETCODE"]==0) {
				this.otList = (event.result.CALTAB1);
				facade.sendNotification(LOAD_DINNER_LIST_COMPLETE, this);
			}
			else {
				facade.sendNotification(LOAD_DINNER_LIST_FAILED, this);
			}
		}

		/**
		 * 서버에서 오류가 발생했을 처리
		 *
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(LOAD_DINNER_LIST_FAILED, this);
		}




		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 *
		 * @param
		 * @return 공지사항 Value Object
		 */
		 private function parseDinnerList(src:ArrayCollection):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection;

			for each(var rec:Object in src)
			{
				var vo:DExpenseListVO = new DExpenseListVO();

				vo.GWAREKEY	= rec["GWAREKEY"];
				vo.WSTATUS 	= rec["WSTATUS"];
				vo.WSTATX 	= rec["WSTATX"];
				vo.PERNR 	= rec["PERNR"];
				vo.BEGDA 	= DateUtil.stringToDateTime(rec["BEGDA"]);
				vo.CDAY 	= rec["CDAY"];
				vo.TEXT1 	= rec["TEXT1"];
				vo.FLAG	 	= rec["FLAG"];
				list.addItem(vo);
			}
			return list;
		}
	}
}